--GO命令用于批量处理Transact-SQL语句
--查询表
SELECT * FROM users
SELECT * FROM courses
SELECT * FROM scores
GO--除注释外，GO命令不能与T-SQL语句位于同一行
--注释
DECLARE @variable1 AS INT=1
DECLARE @variable2 AS FLOAT
SET @variable1=3
SELECT @variable2=1.5
SELECT @variable1 AS 'variable1 value'
PRINT @variable2
/*注释*/
GO
--打印九九乘法表
DECLARE @a AS INT=1
WHILE @a<=9 BEGIN
DECLARE @b AS INT=1
WHILE @b<=@a BEGIN
IF @b<@a
PRINT CONVERT(VARCHAR,@a)+'*'+CONVERT(VARCHAR,@b)+'='+CONVERT(VARCHAR,@a*@b)+CHAR(9)
ELSE
PRINT CONVERT(VARCHAR,@a)+'*'+CONVERT(VARCHAR,@b)+'='+CONVERT(VARCHAR,@a*@b)+CHAR(10)
SET @b+=1
END
SET @a+=1
END
GO
--GOTO语句的使用（可嵌套）
DECLARE @c INT=0
there1:
WHILE @c<5 BEGIN
SET @c+=1
GOTO there2
END
there2:IF @c<3 PRINT '@c<3'
IF @c<5 GOTO there1
PRINT '@c='+CONVERT(VARCHAR,@c)
GO
--生成错误信息
EXECUTE sp_addmessage 50001,1,'THIS IS A ERROR MESSAGE.','us_english',TRUE,REPLACE
GO
--处理错误信息
RAISERROR(50001,1,1)
GO
--删除错误信息
EXECUTE sp_dropmessage 50001,'ALL'
GO
